package 
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import loader.Asset;
	import loader.AssetData;
	import loader.AssetLoader;
	import loader.ExternalLoader;

	
	
	/**
	 * ...
	 * @author SChabanov
	 */
	public class LoaderTest extends Sprite 
	{
		
		private var list:Vector.<AssetData>;
						
		
		private var _loaddXml:XML;
		
		public function Main():void 
		{		
			init();			
		}
		
		private function init(e:Event = null):void 
		{
			

			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
												
			list = new Vector.<AssetData>();
			list.push(new AssetData("ui.components.TestClass","assets/TestClass.swf",0));
			list.push(new AssetData("pic1", "http://harpers.org/media/image/blogs/misc/mr-photo-op.jpg", 0,"group1"));
			//list.push(new AssetData("xml", "assets/roster.xml", 3,"group1"));
			list.push(new AssetData("pic2","http://upload.wikimedia.org/wikipedia/commons/e/e4/Ferdinand_Bol_-_Aegina_wacht_op_de_komst_van_Zeus.jpg",0,""));
			list.push(new AssetData("pic3","http://static.thehollywoodgossip.com/images/gallery/op-ad-campaign.jpg",0,""));
			list.push(new AssetData("pic4","http://www.ru-iphone.com/files/Apple-PC-Ads.jpg",0,"group1"));
			list.push(new AssetData("pic5","http://www.smashingapps.com/wp-content/uploads/2008/12/coffee-machine-ads.jpg",0,"group1"));
			list.push(new AssetData("pic6","assets/378393_m.jpg"));
			list.push(new AssetData("pic7","assets/386240_m.jpg"));
			list.push(new AssetData("pic8","assets/387840_m.jpg",6));
			list.push(new AssetData("pic9","assets/500783[1].jpg",5));
					
			//ExternalLoader.addFiles(list);
			
			ExternalLoader.addEventListener(ExternalLoader.ALL_LOADED, onAllLoadedHandler);
			ExternalLoader.addEventListener(ExternalLoader.GROUP_LOADED, onGroupLoadedHandler);
			ExternalLoader.addEventListener(ExternalLoader.TOTAL_PROGRESS, onProgress);
			ExternalLoader.addEventListener(ExternalLoader.RESOURCE_LOADED, onItemLoaded);
			
			ExternalLoader.load();
			//ExternalLoader.load();
			var aloader:AssetLoader
			var j:int
			for (j = 0; j < list.length; j++) 
			{				
				aloader = new AssetLoader(list[j]);
				aloader.width  = 100;
				aloader.height = 100;
				aloader.drawBorder();
				aloader.aspectRatio = true;
				//aloader.proportional = true;
				aloader.x = aloader.width * j;
				aloader.centerContent = true;
				addChild(aloader);
				//aloader.show();
				
			}
		}	
		private function onGroupLoadedHandler(e:Event):void 
		{
			
		}
		
		private function onItemProgress(e:Event):void 
		{
			//trace(ExternalLoader.lastLoadedResource.percentLoaded);
		}
		
		private function onItemLoadedHandler(e:Event):void 
		{
			
			//addChild(ExternalLoader.lastLoadedResource.content);
		
		}
		
		private function onProgress(e:Event):void 
		{
			trace(int(ExternalLoader.percentTotal));
		}
		
		private function onItemLoaded(e:Event):void 
		{
			
			if (ExternalLoader.lastLoadedResource.resourceType == Asset.TEXT)
			{
				//_loaddXml = ExternalLoader.lastLoadedResource.xmlData;
			}
			/*if (ExternalLoader.lastLoadedResource && ExternalLoader.lastLoadedResource.isLoaded)
			{
				trace(ExternalLoader.lastLoadedResource.name)
				addChild(ExternalLoader.lastLoadedResource.linfo.content);
			}*/
			//
		}
		
		private function onAllLoadedHandler(e:Event):void 
		{
			
			/*trace(_loaddXml);
			var asset:Asset = ExternalLoader.getAsset("ui.components.TestClass");
			
			var cls:Class = ExternalLoader.getClass(asset.name) as Class;
			if (cls)
			{
				addChild(new cls());
			}*/
		}
		
		private function onAssetLoadedHandler(e:Event):void 
		{
		
		}		
						
	}
	
}